<?php
/**
 * Created by PhpStorm.
 * User: hang
 * Date: 2021/12/12
 * Time: 22:42
 */
$bankcard = $_POST['bankcard'];
$pwd = $_POST['pwd'];
$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
$result = $conn->query('select a.RealName,b.CardNo,b.CardPwd from bankcard b join accountinfo a on a.AccountId = b.AccountId');
$userKey = md5($bankcard.$pwd);
session_start();
$a = false;
while (true){
    $data = $result->fetch_assoc();
    if (empty($data)){
        break;
    }
    if ($bankcard==$data['CardNo'] && $pwd==$data['CardPwd']){
        setcookie('key',$userKey,time()+24*3600,'/');
        $_SESSION[$userKey] = [
            'RealName'=>$data['RealName'],
            'CardNo'=>$bankcard,
            'CardPwd'=>$pwd
        ];
        $a = true;
    }
}
if ($a){
    echo '登录成功！<a href="user.php">去登陆</a>';
}else{
    echo '登录失败！';
}